package com.ehome.poct.base.dao.device.repository;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.core.page.Page;
import com.ehome.mybatisplus.support.AbstractCrudRepository;
import com.ehome.poct.base.api.dto.device.TestDeviceQrcodePrintHisHeadDTO;
import com.ehome.poct.base.api.vo.device.QrcodePrintHisVO;
import com.ehome.poct.base.dao.device.entity.TestDeviceQrcodePrintHisHeadDO;
import com.ehome.poct.base.dao.device.mapper.TestDeviceQrcodePrintHisHeadMapper;
import com.ehome.poct.base.dao.mapping.DeviceQrcodePrintMapping;
import com.ehome.poct.base.device.repository.TestDeviceQrcodePrintHisHeadRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 扫码打印头表RepositoryImpl
 *
 * @author ehome
 * @Date 2022-07-14 15:52
 */
@Repository
public class TestDeviceQrcodePrintHisHeadRepositoryImpl extends AbstractCrudRepository<TestDeviceQrcodePrintHisHeadDO, TestDeviceQrcodePrintHisHeadDTO> implements TestDeviceQrcodePrintHisHeadRepository {

    @Autowired
    private TestDeviceQrcodePrintHisHeadMapper headMapper;
    @Autowired
    private DeviceQrcodePrintMapping printMapping;
    @Override
    public Page<QrcodePrintHisVO> pageList(Integer pageIndex, Integer pageSize){
        var pagedatas = headMapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageIndex,pageSize), Wrappers.<TestDeviceQrcodePrintHisHeadDO>lambdaQuery()
                .orderByDesc(TestDeviceQrcodePrintHisHeadDO::getPrintDate));

        Page<QrcodePrintHisVO> page = new Page<>();
        page.setCurrent((int) pagedatas.getCurrent());
        page.setSize((int) pagedatas.getSize());
        page.setTotal((int)pagedatas.getTotal());
        page.setList(printMapping.toList(pagedatas.getRecords()));
        return page;
    }
}
